{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee414105-a370-4578-be07-11c5cc9ada43",
   "metadata": {},
   "outputs": [],
   "source": [
    "from ngsolve import *\n",
    "from ngsolve.webgui import *\n",
    "\n",
    "from netgen.geom2d import unit_square\n",
    "from netgen.occ import unit_cube\n",
    "m = unit_cube.GenerateMesh(maxh=.4)\n",
    "\n",
    "mesh = Mesh(m)\n",
    "fes = H1(mesh, order=3)\n",
    "#fes = L2(mesh, order=3) # L2 not working yet (some DiffOps missing in Archive registration)\n",
    "u = GridFunction(fes)\n",
    "u.Set(x*y)\n",
    "from webgui_jupyter_widgets import *\n",
    "import ngsolve.comp as comp\n",
    "class NewWebGLScene(BaseWebGuiScene):\n",
    "    def __init__(self, mesh, cf, binary=True, order=1):\n",
    "        self.mesh = mesh\n",
    "        self.cf = cf\n",
    "        self.binary = binary\n",
    "        self.order = order\n",
    "    def GetData(self, set_minmax=True):\n",
    "        return {\n",
    "                \"type\": \"BinaryArchive\" if self.binary else \"TextArchive\",\n",
    "                \"data\": comp.ToArchive(self.mesh, self.cf, self.binary),\n",
    "                \"order\": self.order\n",
    "        }\n",
    "\n",
    "cf = CF((x,y,z,u))\n",
    "scene = NewWebGLScene(mesh, cf, True, order=2)\n",
    "data = scene.GetData()\n",
    "\n",
    "scene.Draw()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ffcce71-f801-4808-a8a8-146498c9fe5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ngsolve.comp as comp\n",
    "comp.ToArchive(x, True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5011d349-8d47-4480-a451-11b9c64f3b97",
   "metadata": {},
   "outputs": [],
   "source": [
    "def Copy(obj, binary=True):\n",
    "    return comp.FromArchiveCF(comp.ToArchive(obj, binary), binary)\n",
    "\n",
    "x1 = Copy(x)\n",
    "print(x,x1)\n",
    "u1 = Copy(u)\n",
    "print(u,u1)\n",
    "print(u.vec)\n",
    "print(u1.vec)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7acd7903-a09b-4b2a-a871-2ef1f95cb789",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "905cdd61-9021-4fc4-875d-fd4d5627d564",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
